package com.wanghlme.nowcoder;

import java.util.ArrayList;

/**
 * @author wanghlme
 * @version 1.0
 */
public class NC_JZ78 {
    public static void main(String[] args) {

    }

    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }

    }

    class Solution {
        ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
            ArrayList<ArrayList<Integer>> result = new ArrayList<>();
            helper(pRoot, 1, result);
            return result;
        }

        private void helper(TreeNode pRoot, int depth, ArrayList<ArrayList<Integer>> list) {
            if (pRoot == null) return;
            if (depth > list.size()) list.add(new ArrayList<>());
            list.get(depth - 1).add(pRoot.val);
            helper(pRoot.left, depth + 1, list);
            helper(pRoot.right, depth + 1, list);
        }
    }
}
